Abstract
Throughout this laboratory, we will use the information from the Cryptocurrency's Book of Orders from various international exchanges, with the primary objective of visualizing and modeling the market's microstructure through it's characteristics and behaviors like Matchine Engine, Levels, Ask-Bid Volumes, etc.
In order to run this notebook, it is necessary to have installed and/or have the requirements.txt file with the following:
The following are the file dependencies that are needed to run this notebook:
Because of the incompatability of the jupyter versions the book of orders were saved as csv.
%%capture
# Install all the pip packages in the requirements.txt
import sys
!{sys.executable} -m pip install -r requirements.txt
# importing all libraries
import warnings
warnings.filterwarnings('ignore')
from datetime import timedelta
import numpy as np
import pandas as pd
import ccxt
import functions as fn
import data as dt
import visualizations as vn
import plotly.express as px
This laboratory focuses on using the information in the cryptocurrencies' Book of Orders to visualize and model the market's microstructure. In order to learn about a market's microstructure it is important to have all the information available, for that reason the market chosen for this project was the cryptocurrecy.
This project starts with obtaining the most accurate and current information of three different exchange markets and three different trading pairs using the ccxt library. The exchange markets chosen were Binance and Bitfinex. The trading pairs chosen were BTC/USDT, ETH/USDT and ADA/USDT. Then the information was organized and summarized taking into account the levels and total bid size and ask size.
For the visualization, graphs of the mid price were generated with the plotly library in order to compare the different time series.
To complete the objetives, the last part of the lab consisted of modeling the microstructure of the market. This was achieved through estimating the Effective Spread based on the Roll model (1984).
Exchange markets:
Trading pairs:
Datetime : timestamp in BO
Ask_size : volume of asks
Ask_price : price of asks
Bid_size : volume of bids
Bid_price : price of bids
Spread : difference between ask and bid
Mid_price : average Top of the Book
VWAP : volume-weighted average price
Close_price : closing price
Levels : trading levels
The data obtained from the ccxt library of the Book of Orders is displayed below:
data_files = dt.data_files
pd.read_csv("files/"+data_files[0]) # it is a dictionary but for visualization terms in the notebook it was downloaded as csv
pd.read_csv("files/"+data_files[1])
pd.read_csv("files/"+data_files[2])
pd.read_csv("files/"+data_files[3])
pd.read_csv("files/"+data_files[4])
pd.read_csv("files/"+data_files[5])
In order to visualize the information obtained from the Book of Orders, a DataFrame was created with the type of exchange market, timestamp, levels, volume of asks, volume of bids, total volume, mid price and VWAP. This created the right structure to then create the time series shown in the following graphs.
series, effective_spreads = fn.consumir_orderbooks(data_files)
binancebtcusdt=series["binance_BTCUSDT"]
binancebtcusdt.head(20)
vn.plots(binancebtcusdt,"binance_BTCUSDT")
binanceethusdt=series["binance_ETHUSDT"]
binanceethusdt.head(20)
vn.plots(binanceethusdt,"binance_ETHUSDT")
bitfinexbtcusdt=series["bitfinex_BTCUSDT"]
bitfinexbtcusdt.head(20)
vn.plots(bitfinexbtcusdt,"bitfinex_BTCUSDT")
bitfinexethusdt=series["bitfinex_ETHUSDT"]
bitfinexethusdt.head(20)
vn.plots(bitfinexethusdt,"bitfinex_ETHUSDT")
huobibtcusdt=series["huobi_BTCUSDT"]
huobibtcusdt.head(20)
vn.plots(huobibtcusdt,"huobi_BTCUSDT")
huobiethusdt=series["huobi_ETHUSDT"]
huobiethusdt.head(20)
vn.plots(huobiethusdt,"huobi_ETHUSDT")
In order to model the microstructure of the market, the Effective Spread was calculated based on Roll's model (1984). This model provides a simple market microstructure model that allows one to estimate the bid-ask spread from observed transaction prices alone, without information on the underlying bid-ask price quotes and the order. The model developed a simple model to estimate the bid–ask spread using the serial covariance of observable trade prices. The model used in this project is the following:
using the series in $t-5$ for $\Delta P_{t-1}$.
effective_spreads["binance_BTCUSDT"].head()
effective_spreads["binance_ETHUSDT"].head()
effective_spreads["bitfinex_BTCUSDT"].head()
effective_spreads["bitfinex_ETHUSDT"].head(15)
effective_spreads["huobi_BTCUSDT"].head(25)
effective_spreads["huobi_ETHUSDT"].head(15)
Understanding the microstructure of exchange markets is essencial for trading as it provides the information to know how the prices in the market are determined. Knowing how the ask, bid, spread and other elements of the pricing can allow us to improve out decision making. The informed decision making can lead to more efficient strategies as it allows us to identify the possible opportunities that arise. This can also be achieved by analyzing the market trends which can also be observed through the microstrucure.
In this lab we were able to understand the relationship between the asks and the bids and how most markets were. Once we knew how the market prioritizes the buys and sells we can understand the changes in prices and spreads which then leads us to knowing how the market works and therefore being able to predict it.
A situation that complicated the execution of this lab was the low volume and movement within the exchange market which generated non conclusive results in terms of the spread. Although we found ourselved with this problem, we were able to analyze some of the exchange markets and some of the trading pairs.
With the different graphs for the mid price, it was interesting to see how the behavior of the mid price varied a lot between each exchange and each trading pair as well as the differences between the effective spread. In these cases we can observe a more efficient market when the effective spread if lower. For the exchange market Huobi we can see a less efficient market in the BTC/USDT trading pair so it could be an indicator that it would be a good decision to avoid that market for that pair. These types of decisions are the ones that can be made when the microstructure of the exchange market is analyzed.
El análisis de microestructuras es una herramienta valiosa para obtener información detallada sobre el comportamiento del mercado. A través de este análisis, puedo identificar patrones de comportamiento del mercado, como la presencia de liquidez, volatilidad y efectos de retroceso, lo que me permite tomar decisiones informadas sobre mis estrategias de inversión.
Además, el análisis de microestructuras ayuda a evaluar la eficiencia del mercado y a identificar oportunidades de negociación al detectar discrepancias de precios entre diferentes mercados. También me permite monitorear la actividad de los inversores y el flujo de órdenes en el mercado, lo que me ayuda a tomar decisiones de inversión más fundamentadas.
Otro beneficio del análisis de microestructuras es que me permite evaluar la calidad de ejecución de mis órdenes, incluyendo la velocidad y la certeza de la ejecución. Esto me da confianza en mis decisiones de inversión y me ayuda a mantenerme informado sobre el rendimiento de mis inversiones.En el laboratorio nos pudimos dar cuenta de las tendencias de cuales exchange markets eran mejores, observamos que el mercado de Huobi era el menos eficiente en el BTC/USDT a comparación del Binance y Bitfinex, por eso con este tipo de analisis pordemos escoger que es lo que nos conviene más a nosotros.
En resumen, el análisis de microestructuras me proporciona información valiosa sobre el comportamiento del mercado y la eficiencia del mismo, lo que me permite tomar decisiones informadas y estratégicas sobre mis inversiones.
Nimalendran, M. (2010). Roll Model. Encyclopedia of Quantitative Finance. https://doi.org/10.1002/9780470061602.eqf18014
Semiparametric Identification of the Bid-Ask Spread in Extended. (2015). Core. https://core.ac.uk/download/pdf/146463242.pdf